
#include "IO.h"
#include "BSP_Delay.h"
#include "BSP_Config.h"

#define WG_HIGH		0
#define WG_LOW		1

static const IO_T wgD0 = {(void*)WG_D0_GP, WG_D0_PIN};
static const IO_T wgD1 = {(void*)WG_D1_GP, WG_D1_PIN};

static uint32_t wgIdleTime;
static uint32_t wgActiveTime;

static void BSP_WG_Idle(void){
	IO_Set(&wgD0, WG_HIGH);
	IO_Set(&wgD1, WG_HIGH);
}

void BSP_WG_Config(uint32_t activeTime, uint32_t idleTime){
	wgActiveTime = activeTime;
	wgIdleTime = idleTime;
}

void BSP_WG_Init(void){
	IO_Config(&wgD0, IO_Mode_OUT);
	IO_Config(&wgD1, IO_Mode_OUT);
	BSP_WG_Idle();
	wgIdleTime = 2000;
	wgActiveTime = 400;
}

void BSP_WG_SendBit(uint8_t b){
	if(b){
		IO_Set(&wgD1, WG_LOW);
	}
	else{
		IO_Set(&wgD0, WG_LOW);
	}
	BSP_StrictDelay_us(wgActiveTime);
	BSP_WG_Idle();
	BSP_StrictDelay_us(wgIdleTime);
}


